import Vue from 'vue'
import App from './App.vue'
import router from './router'
import vuex from 'vuex'
import Vant from 'vant'
import store from './store'
import 'vant/lib/index.css';
import axios from 'axios'
import VueAxios from 'vue-axios'
import vueScroller from 'vue-scroller'
import VueI18n from 'vue-i18n'
import Vueqrcode from '@xkeshi/vue-qrcode'
import loading from './views/loading'
import { getCookie } from './language/changeType'
import VCharts from 'v-charts'
import api from './http/http'

Vue.component('loading',loading)
Vue.prototype.imgHost = 'https://ht.oec.ink'
Vue.component('qrcode', Vueqrcode);
Vue.use(VueI18n)
Vue.use(vueScroller)
Vue.use(vuex)
Vue.use(Vant)
Vue.use(VCharts)
Vue.use(VueAxios, axios)
Vue.prototype.$api = api



const i18n = new VueI18n({
  locale:getCookie(),
  messages:{
    'zh':require('./language/oeczh'),
    'en':require('./language/oecen'),
    'koren':require('./language/oekoren'),
    'japan':require('./language/oejapan'),
  }
})
Vue.config.productionTip = false
router.beforeEach((to, from, next) => {
    if(to.path != '/login'){
        if (localStorage.user) {
            next()
        } else if(to.path == '/register'){
            next()
        }else if(to.path == '/forget'){
            next()
        }else {
            next('/login')
        }
    }else{
        next()
    }
});

new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')
